package com.lagou.goods.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lagou.common.pojo.Goods;
import com.lagou.common.pojo.GoodsVo;
import com.lagou.goods.mapper.GoodsMapper;
import com.lagou.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongProject: lagou-parent
 * @author: 胡恺恺
 * @createTime: 2021/1/29  14:21
 * @Description:
 */
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    /**
     * 通过id查询商品
     */
    @Override
    public Goods queryById(Integer id) {
        return goodsMapper.selectById(id);
    }

    /**
     * 通过id删除商品
     */
    @Override
    public int deleteById(Integer id) {
        return goodsMapper.deleteById(id);
    }

    /**
     * 通过id编辑商品
     */
    @Override
    public int updateById(Goods goods) {
        return goodsMapper.updateById(goods);
    }

    // 分页及多条件查询
    @Override
    public PageInfo<Goods> queryByPage(GoodsVo goodsVo) {
        PageHelper.startPage(goodsVo.getCurrentPage(),goodsVo.getPageSize());
        List<Goods> allUserByPage = goodsMapper.queryByPage(goodsVo);

        PageInfo<Goods> pageInfo = new PageInfo<>(allUserByPage);
        return pageInfo;
    }
}
